package com.runfast.paotui.web.controller.user;

import com.runfast.common.utils.TokenUtil;
import com.runfast.common.web.controller.BaseController;
import com.runfast.common.web.entity.Result;
import com.runfast.common.web.entity.ResultCode;
import com.runfast.paotui.dao.model.*;
import com.runfast.paotui.service.CatalogService;
import com.runfast.paotui.service.RunfastAgentbusinessService;
import com.runfast.paotui.service.RunfastShopperService;
import org.apache.commons.lang3.Validate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.runfast.paotui.dao.type.ListToStringTypeHandler.separator;

/**
 * 首页接口
 */
@RestController
@RequestMapping(value = "/api/user/home",headers = "token")
public class HomeController extends BaseController<Catalog, Integer> {

    @Autowired
    private RunfastAgentbusinessService agentbusinessService;

    @Autowired
    private RunfastShopperService shopperService;


    /**
     * 获取用户附件骑手数量
     * @param userLng 用户经度
     * @param userLat 用户纬度
     * @param token
     * @return
     */
    @PostMapping("/driverCountNearBy")
    public Result driverCountNearBy(@RequestParam double userLng, @RequestParam double userLat, @RequestHeader String token) {
        RunfastAgentbusiness agentNearBy = agentbusinessService.getAgentNearBy(userLng, userLat);

        if(agentNearBy==null)return Result.fail(ResultCode.AGENT_NEAR_BY_NOT_EXIST);
        RunfastShopperExample shopperExample = new RunfastShopperExample();
        shopperExample.createCriteria().andAgentIdEqualTo(agentNearBy.getId());
        long count = shopperService.countByExample(shopperExample);
        return Result.ok("", count);
    }



}
